package javaAPI.StringPractice;

import java.util.Scanner;
import java.util.StringJoiner;

public class StringPractice1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个字符串");
        String str;
        while (true) {
            str = sc.next();
            boolean flag = check(str);
            if (flag) {
                break;
            } else {
                System.out.println("当前字符串不符合规则，请重新输入");
                continue;
            }
        }
        StringJoiner sj = new StringJoiner(",", "", "");
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            int number = c - 48;//使用Switch语句就可以不写此行代码。应为Switch已将数字转为罗马数字;
            String number1 = changeNumber(number);//将数字转为罗马数字
            sj.add(number1);
        }
        System.out.println(sj);
    }

    public static boolean check(String str) {
        if (str.length() > 9) {
            return false;
        }
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (c > '9' || c < '0') {
                return false;
            }
        }
        return true;
    }

    public static String changeNumber(int number) {
        String[] arr = {"", "Ⅰ", "Ⅱ", "Ⅲ", "Ⅳ", "Ⅴ", "Ⅵ", "Ⅶ", "Ⅷ", "Ⅸ" };
        return arr[number];
    }
}
    /*public static String changenumber(char number){
        String str;
        switch (number){                    //String str=switch(number){
                                            //   case '1'->"Ⅰ";以此类推                 }
            case '0'->str="";
            case '1'->str="Ⅰ";
            case '2'->str="Ⅱ";
            case '3'->str="Ⅲ";
            case '4'->str="Ⅳ";
            case '5'->str="Ⅴ";
            case '6'->str="Ⅵ";
            case '7'->str="Ⅶ";
            case '8'->str="Ⅷ";
            case '9'->str="Ⅸ";
            default -> str="";
        }
        return str;
    }
*/


